<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

use think\facade\Route;

Route::pattern('id', '\d+');

Route::get('/', function(){
    dump("Index");
    return welcome();
});
/**
 * 后台管理模块
 */
Route::group('admin', function(){
    // 登录模块
    Route::group('login', function(){
        Route::get('/', 'admin/Login/login');
        Route::post('input', 'admin/Login/input');
        Route::get('logout', 'admin/Login/logout');
    });

    //rbac
    Route::group('rbac', function(){
        Route::get('table', function(){
            (new \gmars\rbac\Rbac())->createTable();
        });
    });

    Route::group('', function(){
        //首页
        Route::get('/', 'admin/Index/index');
        Route::get('welcome', 'admin/Index/welcome');
        Route::get('icon', 'admin/Index/getIcon');
        //公共操作
        Route::controller('common', 'admin/Common');
        // 管理员模块
        Route::group('admin', function(){
            Route::get('admin/skin/:skin','admin/admin.Administrator/skin')->validate('app\admin\validate\Admin', 'skin');
            Route::get('admin/status/:id', 'admin/admin.Administrator/status')->model('\app\admin\model\admin\Admin');
            Route::get('admin/only', 'admin/admin.Administrator/only');
            Route::delete('admin/destory', 'admin/admin.Administrator/destory');
            Route::resource('admin', 'admin/admin.Administrator')->model('\app\admin\model\admin\Admin');
            Route::get('permission/status/:id', 'admin/admin.Permission/status')->model('\app\admin\model\admin\Permission');
            Route::get('permission/auto', 'admin/admin.Permission/auto');
            Route::delete('permission/destory', 'admin/admin.Permission/destory');
            Route::resource('permission', 'admin/admin.Permission');
            Route::get('permissionCategory/status/:id', 'admin/admin.PermissionCategory/status')->model('\app\admin\model\admin\PermissionCategory');
            Route::get('permissionCategory/only', 'admin/admin.PermissionCategory/only');
            Route::delete('permissionCategory/destory', 'admin/admin.PermissionCategory/destory');
            Route::resource('permissionCategory', 'admin/admin.PermissionCategory');
            Route::get('roles/status/:id', 'admin/admin.Roles/status')->model('\app\admin\model\admin\Role');
            Route::delete('roles/destory', 'admin/admin.Roles/destory');
            Route::resource('roles', 'admin/admin.Roles');
            Route::get('menus/status/:id', 'admin/admin.Menus/status')->model('\app\admin\model\admin\Menus');
            Route::get('menus/only', 'admin/admin.Menus/only');
            Route::delete('menus/destory', 'admin/admin.Menus/destory');
            Route::resource('menus', 'admin/admin.Menus')->model('\app\admin\model\admin\Menus');
        });
        // 课程模块
        Route::group('curriculum', function () {
            Route::delete('teacher/destory', 'admin/curriculum.Teacher/destory');
            Route::resource('teacher', 'admin/curriculum.Teacher')->model('\app\admin\model\curriculum\Teacher');
            Route::delete('curriculum/destory', 'admin/curriculum.Curriculum/destory');
            Route::resource('curriculum', 'admin/curriculum.Curriculum')->model('\app\admin\model\curriculum\Curriculum');
            Route::delete('schoolTimetable/destory', 'admin/curriculum.SchoolTimetable/destory');
            Route::resource('schoolTimetable', 'admin/curriculum.SchoolTimetable')->model('\app\admin\model\curriculum\SchoolTimetable');
        });
        // 营销模块
        Route::group('marketing', function () {
            Route::delete('coupons/destory', 'admin/marketing.Coupons/destory');
            Route::resource('coupons', 'admin/marketing.Coupons')->model('\app\admin\model\marketing\Coupons');
        });
        // 用户模块
        Route::group('user', function () {
            Route::resource('user', 'admin/user.User')->model('\app\admin\model\user\User');
            Route::resource('address', 'admin/user.Address')->model('\app\admin\model\user\Address');
        });
        // 试题模块
        Route::group('questions', function () {
            Route::delete('question/destory', 'admin/questions.Question/destory');
            Route::resource('question', 'admin/questions.Question')->model('\app\admin\model\questions\Question');
            Route::delete('answer/destory', 'admin/questions.Answer/destory');
            Route::resource('answer', 'admin/questions.Answer')->model('\app\admin\model\questions\Answer');
            Route::delete('examinationType/destory', 'admin/questions.ExaminationType/destory');
            Route::resource('examinationType', 'admin/questions.ExaminationType')->model('\app\admin\model\questions\ExaminationType');
            Route::delete('questionCategory/destory', 'admin/questions.QuestionCategory/destory');
            Route::resource('questionCategory', 'admin/questions.QuestionCategory')->model('\app\admin\model\questions\QuestionCategory');
        });
        // 订单模块
        Route::group('order', function () {
            Route::delete('order/destory', 'admin/order.Order/destory');
            Route::resource('order', 'admin/order.Order')->model('\app\admin\model\order\Order');
        });
    })->middleware([
        \app\http\middleware\IfLogin::class,
        \app\http\middleware\AuthUpdate::class
    ]);
});

//接口管理模块
Route::group('v1', function(){
    // 接口设计
    Route::group('api', function(){
        // 分组用于验证TOKEN
        Route::group('', function(){
            //问题模块
            Route::group('questions', function(){
                Route::get('examinationType', 'questions.ExaminationType/getType');
                Route::get('examinationType/lists', 'questions.ExaminationType/lists');
                Route::get('answer/:id', 'questions.Question/answer')->validate('app\api\validate\questions\Question', 'answer');
                Route::get('recommend/:type', 'questions.Question/recommend')->validate('app\api\validate\questions\Question', 'recommend');
                Route::get('category/:category', 'questions.Question/category')->validate('app\api\validate\questions\Question', 'category');
                Route::get('doAnswer/:id', 'questions.Question/doAnswer')->validate('app\api\validate\questions\Question', 'answer');
                Route::group('collection', function(){
                    Route::get('get/:aid', 'questions.QuestionCollection/get')->validate('app\api\validate\questions\QuestionCollection', 'get');
                    Route::get('collection/:aid', 'questions.QuestionCollection/collection')->validate('app\api\validate\questions\QuestionCollection', 'get');
                    Route::get('lists', 'questions.QuestionCollection/lists');
                    Route::get('read/:id', 'questions.QuestionCollection/read');
                });
                Route::get('examination/chapter', 'questions.QuestionCategory/chapter');
                Route::post('submission', 'questions.Question/submission')->validate('app\api\validate\questions\Question', 'submission');
                Route::get('wrong', 'questions.Question/wrong');
                Route::get('wrongAnswer/:id', 'questions.Question/wrongAnswer');
                Route::get('answer/read/:id', 'questions.Answer/read');
            });
            // 课程模块
            Route::group('curriculum', function(){
                Route::get('lists/:category', 'curriculum.Curriculum/lists')->validate('app\api\validate\curriculum\Curriculum', 'list');
                Route::get('detail/:id', 'curriculum.Curriculum/detail')->model('id','\app\api\model\curriculum\Curriculum');
                Route::get('order/:id', 'curriculum.Curriculum/order')->model('id','\app\api\model\curriculum\Curriculum');
                Route::get('mine/lists', 'curriculum.Curriculum/mine');
            });
            // 订单模块
            Route::group('order', function(){
                Route::post('set', 'set')->validate('\app\api\validate\order\Order', 'set');
                Route::get('lists', 'lists');
                Route::get('read/:id', 'read');
                Route::get('cancel/:id', 'cancel');
            })->prefix('api/order.Order/');
        })->middleware([
            \app\http\middleware\CheckToken::class
        ]);
        // 用户模块
        Route::group('user', function(){
            Route::get('oauth2', 'user.User/oAuth2')->validate('app\api\validate\user\User', 'oauth2');
            Route::group('', function(){
                Route::post('info', 'user.User/Info')->validate('app\api\validate\user\User', 'info');
                Route::get('coupons', 'user.UserCoupons/lists');
                Route::post('coupons/available', 'user.UserCoupons/available')->validate('app\api\validate\user\UserCoupons', 'available');
                Route::get('examinationType', 'questions.ExaminationType/mine');
                Route::post('setting/examinationType', 'questions.ExaminationType/setting')->validate('app\api\validate\questions\UserExaminationType', 'setting');
            })->middleware([
                \app\http\middleware\CheckToken::class
            ]);
        });
        Route::group('notify', function(){
            Route::any('payment/:state', 'notify.Payment/:state');
        });
    })->prefix('api/');
});

return [

];
